#==============================================================================
# Theta Scripting Engine - Bladeblitz by privateer
#==============================================================================
# ► Version  : 1.0
#==============================================================================
# ► Introduction
# This script will enable you to emulate Bladeblitz skills in your game.
# Bladeblitz skills allow you to attack enemies but the damage is multiplied
# with a certain rate. Attack here means you physically attack the enemies as
# if you use the "Attack" command.
#==============================================================================
# ► Instruction
# Just put this script anywhere below Scene_Debug but above Main.
#==============================================================================
# ► Compatibility
# Designed and tested for DBS. May or not work with exotic CBS and/or scripts
# that alter how an action is chosen, how attacks work, or how skills work.
#==============================================================================
# ► Additonal Informations
# The attack's scope and animations are determined by the skill's scope and
# the user's animations.
#==============================================================================

module TSE
  module Bladeblitz
    # Skill ID(s) that you want to be Bladeblitz skills.
    BLADEBLITZ_SKILLS = [83]
    
    # Rate multiplied with the damage dealt by Bladeblitz skills.
    # For example, if you set it to 2, the damage will be doubled.
    DAMAGE_RATE = 0.75
  end
end

#==============================================================================
# DON'T EDIT ANY FURTHER UNLESS YOU KNOW WHAT YOU'RE DOING!
#==============================================================================

$imported = {} if $imported.nil?
$imported["TSE-Bladeblitz"] = true

class RPG::Skill
  def bladeblitz_skill?
    TSE::Bladeblitz::BLADEBLITZ_SKILLS.include?(id)
  end
end

class Scene_Battle
  alias tse_bladeblitz_make_skill_action_result make_skill_action_result
  def make_skill_action_result
    if $data_skills[@active_battler.current_action.skill_id].bladeblitz_skill?
      unless @active_battler.current_action.forcing
        unless @active_battler.skill_can_use?(@skill.id)
          $game_temp.forcing_battler = nil
          @phase4_step = 1
          return
        end
      end
      @active_battler.sp -= @skill.sp_cost
      @status_window.refresh
      @help_window.set_text(@skill.name, 1)
      @animation1_id = @active_battler.animation1_id
      @animation2_id = @active_battler.animation2_id
      @common_event_id = @skill.common_event_id
      set_target_battlers(@skill.scope)
      for target in @target_battlers
        target.using_bladeblitz = true
        target.attack_effect(@active_battler)
      end
    else
      return tse_bladeblitz_make_skill_action_result
    end
  end
end

class Game_Battler
  attr_accessor :using_bladeblitz
  alias tse_bladeblitz_init initialize
  def initialize
    tse_bladeblitz_init
    @using_bladeblitz = false
  end
  alias tse_bladeblitz_attack_effect attack_effect
  def attack_effect(attacker)
    old_hp = self.hp
    tse_bladeblitz_attack_effect(attacker)
    if @using_bladeblitz and self.damage.is_a?(Numeric)
      self.hp = old_hp
      self.damage = (self.damage * TSE::Bladeblitz::DAMAGE_RATE).round
      self.hp -= self.damage
      @using_bladeblitz = false
    end
    return true
  end
end
